package com.iyao_app.util;

import android.text.TextUtils;

import java.math.BigDecimal;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/12/13.
 */

public class CountUtils {
    public static String getCount(String count) {
        if (!TextUtils.isEmpty(count)) {
            return getCount(Integer.parseInt(count));
        } else {
            return "0";
        }
    }

    public static String getCount(int count) {
        String mCount = null;
        if (count >= 10000) {
            double i = count / 10000.00;
            if (count % 10000 == 0) {
                mCount = (int) i + "w";
            } else {
                BigDecimal df = new BigDecimal(i);
                mCount = df.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "w";
            }
        } else if (count >= 1000) {
            double i = count / 1000.0;
            if (count % 1000 == 0) {
                mCount = (int) i + "k";
            } else {
                BigDecimal df = new BigDecimal(i);
                mCount = df.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue() + "k";
            }
        } else {
            mCount = String.valueOf(count);
        }
        return mCount;
    }
}
